package flextestng.testing
{
	public class Assert
	{
		public static function assertEquals(expected:Object, actual:Object, message:String = null):void
		{
			if (expected === actual) {
				return;
			}
			
			failNotEquals(expected, actual, message);
		}
		
		public static function assertFalse(condition:Boolean, message:String = null):void
		{
			if (condition) {
				fail(message);
			}
		}
		
		public static function assertNotNull(object:Object, message:String = null):void
		{
			assertTrue(object != null, message);
		}
		
		public static function assertNull(object:Object, message:String = null):void
		{
			assertTrue(object == null, message);
		}
		
		public static function assertTrue(condition:Boolean, message:String = null):void
		{
			if (!condition) {
				fail(message);
			}
		}
		
		public static function assertSame(expected:Object, actual:Object, message:String = null):void
		{
			if (expected == actual) {
				return;
			}
			
			failNotSame(expected, actual, message);
		}
		
		public static function assertNotSame(expected:Object, actual:Object, message:String = null):void
		{
			if (expected != actual) {
				return;
			}
			
			failSame(expected, actual, message);
		}
		
		public static function fail(message:String = null):void
		{
			throw new AssertionError(message);
		}
		
		public static function failNotEquals(expected:Object, actual:Object, message:String = null):void
		{
			fail(format(expected, actual, message));
		}
		
		public static function failSame(expected:Object, actual:Object, message:String = null):void
		{
			var formatted:String = "";
			
			if (message != null) {
				formatted = message + " ";
			}
			
			fail(formatted + "expected not same");
		}
		
		public static function failNotSame(expected:Object, actual:Object, message:String = null):void
		{
			var formatted:String = "";
			
			if (message != null) {
				formatted = message + " ";
			}
			
			fail(formatted + "expected same:<" + expected + "> was not:<" + actual + ">");
		}
		
		public static function format(expected:Object, actual:Object, message:String):String
		{
			var formatted:String = "";
			
			if (message != null) {
				formatted = message + " ";
			}
			
			return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
		}
	}
}